package cluster.links;
import java.util.ArrayList;

import common.Word;
import common.Config;

class LinkRecord{
	private String keyword;
    private float weight;
	public ArrayList<LinkItem> linkList = new ArrayList<LinkItem>();

    public LinkRecord( Word w ){
        this.keyword = w.getKeyword();
        this.weight = w.getWeight();
	}
	
    public LinkRecord( String keyword ){
	    	this.keyword = keyword;
        }
    
	public String getKeyword(){
		return keyword;
	}
  
	public float getWeight(){
		return weight;
	}

    public void addLink( LinkItem link ){
	    linkList.add( link );
	}
    
    public void newLink( String keyword ){
		LinkItem newit = new LinkItem( keyword,1 );
        linkList.add( newit );
	}
    public int numLinks(){
	    return linkList.size();
    	}
    	/**
    	 * remove the links whose num  < Config.minLinks
    	 */
    public void pruneLinks(){
	    	int minLinks = Config.minLinks;
	    	
	    for( int i=0;i<linkList.size(); ){
		    if( linkList.get(i).getNum() < minLinks ){
			    linkList.remove(i);
		    	}
		    else{
		    		i++;
		    	}
	    	}
    	}
	/**	
	 * find the link which contain a specific keyword
	 * @param keyword
	 * @return the link finded,if not exsits,return null
	 */
    public LinkItem findLink( String keyword ){
	    for( int i=0;i<linkList.size();i++ ){ 
            LinkItem item = linkList.get(i);
            if( item.getKeyword().equals(keyword) ){
                return item;
			}
		}
	    return null;
	}

    public String toString(){
        return keyword+","+weight+","+linkList.toString();
    }

}
